/*---------------------------------------------------------------------
 * File name: uorb.h
 *
 * Copyright (c) <2020-2022>, <ChenLong>
 *
 * All rights reserved.
 *
 * Author: ChenLong
 * Email: worldlong@foxmail.com
 *--------------------------------------------------------------------*/
#pragma once
/*
*/
#include "rtthread.h"
#include "list/list.h"
/*
*/
#define UORB_DATA(data) (void*)&data
/*
*/
enum UORBType
{
  UORB_TYPE_NONE,
  UORB_TYPE_PUBLISHER,
  UORB_TYPE_SUBSCRIBER,
};
/*
*/
struct UORBNode
{
  UORBType type;
  int16_t  id;
  uint16_t  size;
  void  *data;
  rt_thread_t thread;
  
  struct UORBNode *id_next;
  struct UORBNode *next;
  struct UORBNode *prev;
};
/*
*/
class UORB
{
public:
  UORB();  //for receiver
  UORB(void *data);//for publisher
  int publish(int id, void* data, int size);
  int subscribe(int id, void* data, int timeout);
private:
  UORBNode _node;
  
  void init(int id, UORBType type);
  int check(void* data);
};







